package uniandes.cupi2.photoViewer.interfaz;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import java.awt.Dimension;

import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.ListSelectionModel;

import uniandes.cupi2.photoViewer.listas.IListaAlbum;

public class PanelAlbum extends JPanel implements ListSelectionListener
{

	private JList listaAlbumes;
	
	private InterfazPhotoViewer principal;
	/**
	 * Create the panel.
	 */
	public PanelAlbum( InterfazPhotoViewer ventana )
	{
		principal = ventana;
		
		setPreferredSize(new Dimension(450, 300));
		setBorder(new TitledBorder(null, "Albumes", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		listaAlbumes = new JList();
		listaAlbumes.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
		listaAlbumes.addListSelectionListener( this );
		listaAlbumes.setMinimumSize(new Dimension(30, 30));
		
		JScrollPane scrollPane = new JScrollPane(listaAlbumes);
		scrollPane.setPreferredSize(new Dimension(270, 250));
		add(scrollPane);
	}
	
	public void actualizar( IListaAlbum albumes)
	{
		listaAlbumes.setListData(albumes.toArray());
		listaAlbumes.setSelectedIndex(0);
	}
	
	@Override
	public void valueChanged(ListSelectionEvent e) 
	{
		if( listaAlbumes.getSelectedValue() != null )
		{
			String album = (String) listaAlbumes.getSelectedValue();
			principal.mostrarInformacion( album );
		}
		
	}

}
